package com.vhuomai.product.mapper;

import com.vhuomai.mybatis.mapper.auto.AutoMapper;
import com.vhuomai.mybatis.mapper.page.Page;
import com.vhuomai.mybatis.mapper.page.PageRequest;
import com.vhuomai.product.dto.ProductBasic;
import com.vhuomai.product.entity.BaseProduct;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author harris
 */
@Mapper
public interface ProductMapper extends AutoMapper <BaseProduct, Integer> {

    @Select("select id, name, head_image, price, sales, view_count, create_time from base_product where id=#{id}")
    BaseProduct findSimpleById(@Param("id") int id);

    @Select("select p.*, s.name as spuName from base_product p "
        + "left join base_spu s on p.spu_id = s.id "
        + "where p.id = #{productId}")
    ProductBasic findBaseOne(@Param("productId") int productId);

    Page <BaseProduct> findByMerchantNo(@Param("merchantNo") int merchantNo, PageRequest request);

    List <BaseProduct> findHomeProduct(@Param("merchantNo") Integer merchantNo, @Param("isHome") Boolean isHome);
}
